using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.Camera;

namespace XGame.UI
{
    [RequireComponent(typeof(Camera))]
    public class CamerLock : MonoBehaviour
    {
        public float FOVSize = 44;
        public FieldOfViewAxis FOVAxis = FieldOfViewAxis.Horizontal;
  
        Camera _Owner;

        public float CamerW,CamreH;
        public float SceenW, SceenH;

        public float SceenWS, SceenHS;
        // Start is called before the first frame update
        void Awake()
        {
            _Owner = GetComponent <Camera> ();
        }
        public float FOVSSS = 0;
        void _suit()
        {
            if (_Owner != null)
            {
                float _ddd= _Owner.pixelWidth * 0.5f / Mathf.Tan(FOVSize*0.5f*Mathf.PI/180f);
                float _aaa = _Owner.pixelHeight * 0.5f / _ddd; 

                FOVSSS = Mathf.Atan(_aaa)*180f*2f/Mathf.PI;
                if (FOVAxis == FieldOfViewAxis.Horizontal)
                    _Owner.fieldOfView = FOVSSS;
                else
                    _Owner.fieldOfView = FOVSize;
                return;
            }


            
        }
        private void Start()
        {
                _suit();

        }

        // Update is called once per frame
        void Update()
        {
            CamerW = _Owner.pixelWidth;
            CamreH = _Owner.pixelHeight;

            SceenWS = _Owner.scaledPixelWidth;
            SceenHS = _Owner.scaledPixelHeight;
            //SceenW = _Owner.
            _suit();

        }
    }
}

